<?php
/**
 * site/edit.phtml
 * Vue des pages d'éditions d'un site
 */
?>
<?php
$title		 = 'Fiche site';
$this->headTitle($title);
$uplRepPhoto	 = str_replace('public/', '', $rep_upload['photo']);
?>

<?php
// variables    
$infoSite	 = $site->libelle;
$dWk		 = array('lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche');
?> 


<div class='content-head'>
    <h3><?php echo $title; ?> : <span id="title-site-libelle"><?php echo $infoSite; ?> </span></h3>
    <div class="toolbar">        
        <button class='btn btn-inverse' onclick="location.href = '<?php echo $this->url('RHX/default', array('controller' => 'site')) ?>';">Revenir à la liste des sites</button>
    </div>
</div>

<div class='content-body fiche-site site-border clear-auto'>
    <div class='site-top '>        
        <div style="margin-top: 20px;" class="inf-site inf-site-violet"> 
	    Libellé : <a href='#' class='' id= 'site-libelle' href='#'  data-name="libelle" data-pk=" <?php echo $site->id; ?>" data-type="text" > <?php echo $site->libelle; ?> </a>
        </div>
    </div>
    <div class='site-left '>
	<div class="cnt-photo-site" >
            <a href='javascript: void(0);' class='cnt-img-site ' id='link-uploadPhoto'>
		<?php
		$photo		 = $site->photo && $site->photo !== '' ? $site->photo : null;
		//$basePath	 = str_replace('public', '', $this->basePath()); 
		$basePath	 = $this->basePath();
		$photoUrl	 = $basePath . ($photo ? '/' . $uplRepPhoto . $photo : '/img/rhx/site-default.jpg');
		?>

		<img id="site-photo" src="<?php echo $photoUrl; ?>" width="320" height="auto">
            </a>
            <a href="#" id="btn-uploadPhotoSite" data-id="<?php echo $site->id; ?>"  class='btn btn-info btn-small' style="display:none; z-index:55555;">
		Télécharger photo
	    </a>
	</div>
	<div class="inf-site inf-site-bleu" style="margin: 20px;">
	    <a href="#" id="site-documents" rel="popover" style="color: #fff;">
		Document(s) du Site (<span id="site-doc-count"><?php echo $siteManager->getCountDoc($site->id) ;?></span>)
	    </a>
	</div>
	<div class='inf-site inf-site-violet' style='margin-top: 53px;'> Siret : 
	    <a href='#' class='' id= 'site-siret' href='#' data-name="siret" data-pk=" <?php echo $site->id; ?>" data-type="text" > <?php echo $site->siret; ?> </a></div>
	<div class='inf-site inf-site-violet'> TVA : 
	    <a href='#' class='' id= 'site-tva' href='#' data-name="tva" data-pk=" <?php echo $site->id; ?>" data-type="text" > <?php echo $site->tva; ?> </a></div>
	<div class='inf-site inf-site-violet'> N° CRT : 
	    <a href='#' class='' id= 'site-crt' href='#' data-name="crt" data-pk=" <?php echo $site->id; ?>" data-type="text"> <?php echo $site->crt; ?> </a></div>
	<div class='inf-site inf-site-violet'> N° Police Assurance : 
	    <a href='#'  class='' id= 'site-assurance' href='#' data-name="assurance" data-pk=" <?php echo $site->id; ?>" data-type="text"> <?php echo $site->assurance; ?> </a></div>       
	<div class='inf-site inf-site-violet'>  N°  d’adhérent Urssaf : 
	    <a href='#'  class='' id= 'site-urssaf' href='#' data-name="urssaf" data-pk=" <?php echo $site->id; ?>" data-type="text"> <?php echo $site->urssaf; ?> </a></div>       

	<div class='inf-site inf-site-beige' style='margin-top: 20px;'> Médecine du travail N° Adhérent : 
	    <a   href='#'  id= 'site-medecine_travail'data-name="medecine_travail" data-pk=" <?php echo $site->id; ?>" data-type="text"> <?php echo $site->medecine_travail; ?>  </a></div>
	<div class='inf-site inf-site-beige'> Centre de Visite :
	    <a href='' id= 'site-centre_visite'data-name="centre_visite" data-pk=" <?php echo $site->id; ?>" data-type="text" > <?php echo $site->centre_visite; ?>  </a></div>   

    </div>

    <div class='site-right'>
	<div  class='inf-site inf-site-bleu' style='margin-top: 20px;' > Adresse : 
	    <a id= 'site-adresse' href='#'class='' data-name="adresse" data-pk=" <?php echo $site->id; ?>" data-type="textarea"> <?php echo $site->adresse; ?></a></div>

	<div class='inf-site inf-site-bleu' > Téléphone : 
	    <a id= 'site-phone' href='#' class=''  data-name="phone" data-pk=" <?php echo $site->id; ?>" data-type="text" ><?php echo $site->phone; ?></a></div>     
	<div class='inf-site inf-site-bleu' style=''> Fax : 
	    <a id= 'site-fax'  href="#" id= '' class=''  data-name="fax" data-pk=" <?php echo $site->id; ?>" data-type="text" ><?php echo $site->fax; ?></a></div>

	<div class='inf-site inf-site-bleu'> Mail :
	    <a href='#' id= 'site-mail' class=''  data-name="mail" data-pk=" <?php echo $site->id; ?>" data-type="text" > <?php echo $site->mail; ?>  </a></div>     
	<div class='inf-site inf-site-bleu' style=''  > Métro : 
	    <a href='' id= 'site-metro' data-name="metro" data-pk=" <?php echo $site->id; ?>" data-type="text" class=''><?php echo $site->metro; ?></a></div>       

	<div class='cnt-inf-site cnt-inf-site-dir clear-auto' style='margin-top: 20px;'>
	    <?php
	    $dir		 = isset($this->directeur) ? $this->directeur : null;
	    $infDir		 = $dir ? $dir->infDir : 'NA';
	    ?>
            <div class='inf-site inf-site-pink ' > Directeur : 
                <a href='' id= 'site-directeur' class='' data-name="directeur_id" data-pk="<?php echo $site->id; ?>" data-type="select"> <?php echo $infDir; ?> </a></div>     
            <div class='inf-site inf-site-pink ' > Marché N° : 
                <a href='' id= 'site-marche' data-name="marche" data-pk="<?php echo $site->id; ?>" data-type="text"> <?php echo $site->marche; ?></a></div>       
	</div>


	<div class='cnt-inf-site clear-auto' style='margin-top: 20px;'>                

	    <div class='inf-site inf-site-white inf-site-border-blue' style='margin-bottom: 6px;'> 
		Horaire du site 
	    </div>
	    <table id='table-site-horaire' class='table table-striped '>
		<thead>
		    <tr>
			<?php foreach ($dWk as $d): ?>
    			<td width='9%'>
				<?php echo strtoupper($d[0]); ?> 

    			</td>
			<?php endforeach; ?>


		    </tr>
		</thead>

		<tbody>
		    <tr>
			<?php foreach ($dWk as $d): ?>
    			<td style=' padding-top: 0 ;padding-bottom: 0 ;'>

    			    <input class="checkbox checkbox-open-state" type="checkbox" value='' <?php echo $horaire->$d ? 'checked' : ''; ?> data-pk='<?php echo $horaire->id; ?>' data-name='<?php echo $d; ?>' data-type_horaire='normal'>
    			</td>
			<?php endforeach; ?>


		    </tr>
		    <tr> 
			<?php foreach ($dWk as $d): ?>
			    <?php $d_ouv = $d . '_ouverture'; ?>

    			<td><a class="hr-ouverture hr-ouverture-<?php echo $d; ?> hr-ouverture-normal-<?php echo $d; ?>" data-title="Heure d'ouverture le <?php echo $d; ?>" data-pk="<?php echo $horaire->id ?>" data-name='<?php echo $d_ouv; ?>' data-viewformat="HH\h mm\m" data-format="HH:mm" data-template="HH:mm" data-type="combodate" href="#" > 
				    <?php
				    if ($horaire->$d):
					$tm	 = strtotime($horaire->$d_ouv);
					$s	 = sprintf("%sh %sm", date("H", $tm), date("i", $tm));

				    else :
					$s = '&nbsp;';
				    endif;
				    echo $s;
				    ?>
    			    </a>
    			</td>

			<?php endforeach; ?>
		    </tr>
		    <tr> 
			<?php foreach ($dWk as $d): ?>
			    <?php $d_fer = $d . '_fermeture'; ?>
    			<td><a class="hr-fermeture hr-fermeture-<?php echo $d; ?> hr-fermeture-normal-<?php echo $d; ?>" data-title="Heure de fermeture le <?php echo $d; ?>" data-pk="<?php echo $horaire->id ?>" data-name='<?php echo $d_fer; ?>' data-viewformat="HH\h mm\m" data-format="HH:mm" data-template="HH:mm" data-type="combodate" href="#"> 
				    <?php
				    if ($horaire->$d):
					$tm	 = strtotime($horaire->$d_fer);
					$s	 = sprintf("%sh %sm", date("H", $tm), date("i", $tm));

				    else :
					$s = '&nbsp;';
				    endif;
				    echo $s;
				    ?>
    			    </a>
    			</td>
			<?php endforeach; ?>
		    </tr>

		</tbody>      
            </table>




	    <!--div  class='cnt-inf-site cnt-inf-site-rib clear-auto' >           
		<a href='javascript: void(0);' class='bt bt-show'>Affichage obligatoire</a>           
	    </div-->

	</div>

	<!-- HORAIRE CONGE -->
	<div class="cnt-inf-site clear-auto" style="margin-top: 20px;">
	    <div class="inf-site inf-site-white inf-site-border-blue" style="margin-bottom: 6px;">
		Horaire du site en période de congés
	    </div>
	    <table id="table-site-conge" class="table table-striped">
		<thead>
		    <tr>
			<?php foreach ($dWk as $d): ?>
    			<td width='9%'>
				<?php echo strtoupper($d[0]); ?> 

    			</td>
			<?php endforeach; ?>
		    </tr>
		</thead>
		<tbody>
		    <tr>
			<?php foreach ($dWk as $d): ?>
    			<td style=' padding-top: 0 ;padding-bottom: 0 ;'>

    			    <input class="checkbox checkbox-open-state" type="checkbox" value='' <?php echo $conge->$d ? 'checked' : ''; ?> data-pk='<?php echo $conge->id; ?>' data-name='<?php echo $d; ?>'  data-type_horaire='conge'>
    			</td>
			<?php endforeach; ?>


		    </tr>
		    <tr> 
			<?php foreach ($dWk as $d): ?>
			    <?php $d_ouv = $d . '_ouverture'; ?>

    			<td><a class="hr-ouverture hr-ouverture-<?php echo $d; ?> hr-ouverture-conge-<?php echo $d; ?>" data-title="Heure d'ouverture le <?php echo $d; ?>" data-pk="<?php echo $conge->id ?>" data-name='<?php echo $d_ouv; ?>' data-viewformat="HH\h mm\m" data-format="HH:mm" data-template="HH:mm" data-type="combodate" href="#" > 
				    <?php
				    if ($conge->$d):
					$tm	 = strtotime($conge->$d_ouv);
					$s	 = sprintf("%sh %sm", date("H", $tm), date("i", $tm));

				    else :
					$s = '&nbsp;';
				    endif;
				    echo $s;
				    ?>
    			    </a>
    			</td>

			<?php endforeach; ?>
		    </tr>
		    <tr> 
			<?php foreach ($dWk as $d): ?>
			    <?php $d_fer = $d . '_fermeture'; ?>
    			<td><a class="hr-fermeture hr-fermeture-<?php echo $d; ?>  hr-fermeture-conge-<?php echo $d; ?>" data-title="Heure de fermeture le <?php echo $d; ?>" data-pk="<?php echo $conge->id ?>" data-name='<?php echo $d_fer; ?>' data-viewformat="HH\h mm\m" data-format="HH:mm" data-template="HH:mm" data-type="combodate" href="#"> 
				    <?php
				    if ($conge->$d):
					$tm	 = strtotime($conge->$d_fer);
					$s	 = sprintf("%sh %sm", date("H", $tm), date("i", $tm));

				    else :
					$s = '&nbsp;';
				    endif;
				    echo $s;
				    ?>
    			    </a>
    			</td>
			<?php endforeach; ?>
		    </tr>
		</tbody>
	    </table>
	</div>

	<!-- HORAIRE EXCEPTIONNEL -->
	<div class="cnt-inf-site clear-auto" style="margin-top: 20px;">
	    <div class="inf-site inf-site-white inf-site-border-blue" style="margin-bottom: 6px;">
		Horaire du site exceptionnel
	    </div>
	    <table id="table-site-exceptionnel" class="table table-striped">
		<thead>
		    <tr>
			<?php foreach ($dWk as $d): ?>
    			<td width='9%'>
				<?php echo strtoupper($d[0]); ?> 

    			</td>
			<?php endforeach; ?>
		    </tr>
		</thead>
		<tbody>
		    <tr>
			<?php foreach ($dWk as $d): ?>
    			<td style=' padding-top: 0 ;padding-bottom: 0 ;'>

    			    <input class="checkbox checkbox-open-state" type="checkbox" value='' <?php echo $exceptionnel->$d ? 'checked' : ''; ?> data-pk='<?php echo $exceptionnel->id; ?>' data-name='<?php echo $d; ?>'  data-type_horaire='exceptionnel'>
    			</td>
			<?php endforeach; ?>


		    </tr>
		    <tr> 
			<?php foreach ($dWk as $d): ?>
			    <?php $d_ouv = $d . '_ouverture'; ?>

    			<td><a class="hr-ouverture hr-ouverture-<?php echo $d; ?> hr-ouverture-exceptionnel-<?php echo $d; ?>" data-title="Heure d'ouverture le <?php echo $d; ?>" data-pk="<?php echo $exceptionnel->id ?>" data-name='<?php echo $d_ouv; ?>' data-viewformat="HH\h mm\m" data-format="HH:mm" data-template="HH:mm" data-type="combodate" href="#" > 
				    <?php
				    if ($exceptionnel->$d):
					$tm	 = strtotime($exceptionnel->$d_ouv);
					$s	 = sprintf("%sh %sm", date("H", $tm), date("i", $tm));

				    else :
					$s = '&nbsp;';
				    endif;
				    echo $s;
				    ?>
    			    </a>
    			</td>

			<?php endforeach; ?>
		    </tr>
		    <tr> 
			<?php foreach ($dWk as $d): ?>
			    <?php $d_fer = $d . '_fermeture'; ?>
    			<td><a class="hr-fermeture hr-fermeture-<?php echo $d; ?> hr-fermeture-exceptionnel-<?php echo $d; ?>" data-title="Heure de fermeture le <?php echo $d; ?>" data-pk="<?php echo $exceptionnel->id ?>" data-name='<?php echo $d_fer; ?>' data-viewformat="HH\h mm\m" data-format="HH:mm" data-template="HH:mm" data-type="combodate" href="#"> 
				    <?php
				    if ($exceptionnel->$d):
					$tm	 = strtotime($exceptionnel->$d_fer);
					$s	 = sprintf("%sh %sm", date("H", $tm), date("i", $tm));

				    else :
					$s = '&nbsp;';
				    endif;
				    echo $s;
				    ?>
    			    </a>
    			</td>
			<?php endforeach; ?>
		    </tr>
		</tbody>
	    </table>
	</div>
    </div>
    <div class='clear-auto'> </div>
    <div class='site-bottom'>   
         <?php /*    
        <div style="margin-top: 20px;" class="inf-site inf-site-bleu"> 
	    &nbsp;
        </div>
        <table id='table-site-tau' class='table table-striped '>
            <thead>
		<tr>
		    <!--th class='first-col'> </th-->
		    <td width='23%'> </td>
		    <?php foreach ($dWk as $d): ?>
    		    <td width='11%'>
			    <?php echo strtoupper($d); ?>
    		    </td>
		    <?php endforeach; ?>
		</tr>
            </thead>

	    <tbody>                  
		<!--tr> 
		    <td class='first-col'> Prévision de CA</td> 
		<?php foreach ($dWk as $d): ?>
		    <?php $d_prevca = $d . '_prevision_ca'; ?>
    		    
    		       <td><a class="tda-prevision-ca " data-title="Prévision CA du <?php echo $d; ?>" data-pk="<?php echo $site->id ?>" data-name='<?php echo $d_prevca; ?>' data-type="text" href="#" > 
		    <?php echo $site->$d_prevca; ?>
    			   </a>
    		       </td>
		<?php endforeach; ?>
		</tr-->

		<tr> 
		    <td class='first-col'>Main d'oeuvre</td> 
		    <?php foreach ($dWk as $d): ?>
			<?php $d_mo = $d . '_main_oeuvre'; ?>

    		    <td><a class="tda-main-oeuvre" data-title="Main d'oeuvre du <?php echo $d; ?>" data-pk="<?php echo $site->id ?>" data-name='<?php echo $d_mo; ?>' data-type="text" href="#" > 
				<?php echo $site->$d_mo; ?>
    			</a>
    		    </td>
		    <?php endforeach; ?>
		</tr>

		<tr> 
		    <td class='first-col'>Nombre de transaction</td> 
		    <?php foreach ($dWk as $d): ?>
			<?php $d_nt = $d . '_nb_transaction'; ?>

    		    <td><a class="tda-nb-transaction" data-title="Nombre de transaction du <?php echo $d; ?>" data-pk="<?php echo $site->id ?>" data-name='<?php echo $d_nt; ?>' data-type="text" href="#" > 
				<?php echo $site->$d_nt; ?>
    			</a>
    		    </td>
		    <?php endforeach; ?>
		</tr>
	    </tbody>      
	</table> */ 
         ?>
    </div>

    <script type='text/javascript'>


	$(function() {

	    /* var site_inf =  ['adresse', 'phone', 'fax', 'metro', 'siret', 'tva', 'crt', 'assurance', 'medecine_travail', 'centre_visite', 'marche'],
	     site_inf_tit = ['Adresse', 'Téléphone', 'Fax', 'Metro', 'Siret', 'TVA', 'N° CRT', "N° Police d'assurance", "Médecine du travail N° Adhérent", "Centre de Visite", "N° Marché"];
	     */
	    var site_inf = {
		'adresse': 'Adresse', 'phone': 'Téléphone', 'fax': 'Fax',
		'metro': 'Metro', 'siret': 'Siret', 'tva': 'TVA',
		'crt': 'N° CRT', 'assurance': "N° Police d'assurance",
		'urssaf': "N° d'adhérent Urssaf",
		'medecine_travail': "Médecine du travail N° Adhérent",
		'centre_visite': "Centre de Visite", 'marche': "N° Marché"
	    };

	    $.each(site_inf, function(k, v) {
		//console.log(k + ' > ' +v);            
		id = 'site-' + k;
		$('#' + id).editable({
		    title: v,
		    url: '<?php echo $this->url('RHX/default', array('controller' => 'site', 'action' => 'editData')) ?>'
		});
	    });

	    $('#site-libelle').editable({
		title: 'Libellé du site',
		url: '<?php echo $this->url('RHX/default', array('controller' => 'site', 'action' => 'editData')) ?>',
		validate: function(v) {
		    $('span#title-site-libelle').text(v);
		}
	    });

	    $('#site-mail').editable({
		title: 'Adresse électronique',
		url: '<?php echo $this->url('RHX/default', array('controller' => 'site', 'action' => 'editData')) ?>',
		validate: function(v) {
		    regExpMail = new RegExp(/^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$/);

		    if (!regExpMail.test(v))
			return 'Adresse mail invalide';
		}
	    });

	    $('#site-directeur').editable({
		title: 'Fax',
		url: '<?php echo $this->url('RHX/default', array('controller' => 'site', 'action' => 'editData')) ?>',
		source: "<?php echo $this->url('RHX/default', array('controller' => 'employe', 'action' => 'jsonDirecteur', 'id' => $site->id)) ?>",
	    });
	    $('.cnt-photo-site').hover(function(e) {
		$('#btn-uploadPhotoSite').css('display', '');
	    }).mouseleave(function(e) {
		$('#btn-uploadPhotoSite').css('display', 'none');
	    });

	    // uploading photo
	    $(['#link-uploadPhoto', '#btn-uploadPhotoSite']).each(function(k, id) {
		$(id).on('click', function(e) {
		    e.preventDefault();
		    uploadWindow = window.open('<?php echo $this->url('RHX/default', array('controller' => 'site', 'action' => 'uploadPhoto', 'id' => $site->id)) ?>', 'UploadWindow', 'menubar=no, scrollbars=no, top=100, left=100, width=500, height=400');
		});
	    });

	    // uploading rib
	    $('#link-uploadRib').on('click', function(e) {
		e.preventDefault();
		uploadWindow = window.open('<?php echo $this->url('RHX/default', array('controller' => 'site', 'action' => 'uploadRib', 'id' => $site->id)) ?>', 'UploadWindow', 'menubar=no, scrollbars=no, top=100, left=100, width=500, height=400');
	    });

	    // horaire site
	    $('.hr-ouverture').each(function() {
		$(this).editable({
		    /*placement: 'right',*/
		    combodate: {
			firstItem: 'name',
			minuteStep: 5
		    },
		    url: "<?php echo $this->url('RHX/default', array('controller' => 'sitehoraire', 'action' => 'saveStringData')) ?>",
		    validate: function(val) {
			new_hour = val.hour() + 'h ' + val.minute() + 'm';

		    },
		    success: function(val) {
			console.log('success');
		    }
		});
	    });
	    $('.hr-fermeture').each(function() {
		$(this).editable({
		    /*placement: 'right',*/
		    combodate: {
			firstItem: 'name',
			minuteStep: 5
		    },
		    url: "<?php echo $this->url('RHX/default', array('controller' => 'sitehoraire', 'action' => 'saveStringData')) ?>",
		    validate: function(val) {
			new_hour = val.hour() + 'h ' + val.minute() + 'm';
			//$(this).html(new_hour);
		    },
		    success: function(val) {
			console.log('success');
		    }
		});
	    });


	    $('.checkbox-open-state').each(function() {
		var $this = $(this),
			init = function() {
			    var day = $this.data('name'),
				    $hrOuv = $('.hr-ouverture-' + day),
				    $hrFer = $('.hr-fermeture-' + day);

			    isChecked = $this.is(':checked') ? 1 : 0;

			    $hrOuv.editable(isChecked ? 'enable' : 'disable');
			    $hrFer.editable(isChecked ? 'enable' : 'disable');
			    if (!isChecked) {
				$hrOuv.html('...');
				$hrFer.html('...');
			    }

			    // design bootstrap
			    $this.checkbox();			  
			};

		// init checkbox 
		init();

		//init onchange
		$this.on('change', function() {
		    var $this = $(this),
			    updateOpenClose = function(pk, day_openState, val) {
				_data = '&pk=' + pk + '&name=' + day_openState + '&value=' + val
				ajaxOC = $.ajax({
				    type: 'post',
				    url: '<?php echo $this->url('RHX/default', array('controller' => 'sitehoraire', 'action' => 'saveStringData')) ?>',
				    data: _data
				});
			    }
		    ;

		    pk = $this.data('pk');
		    day = $this.data('name');
                    type_horaire = $this.data('type_horaire');
		    isChecked = $this.is(':checked') ? 1 : 0;

		    _data = '&pk=' + pk + '&name=' + day + '&value=' + isChecked;
		    ajax = $.ajax({
			type: 'post',
			url: '<?php echo $this->url('RHX/default', array('controller' => 'sitehoraire', 'action' => 'saveStringData')) ?>',
			data: _data
		    });
		    ajax.done(function(result) {
                        /*
			var $hrOuv = $('.hr-ouverture-' + day),
				$hrFer = $('.hr-fermeture-' + day);*/
                        var $hrOuv =  $('.hr-ouverture-'+ type_horaire +'-' + day),
                            $hrFer =  $('.hr-fermeture-' + type_horaire+ '-' + day);
                                
			// enable/disable
			$hrOuv.editable(isChecked ? 'enable' : 'disable');
			$hrFer.editable(isChecked ? 'enable' : 'disable');

			// update 
			if (isChecked) {
			    updateOpenClose(pk, day + '_ouverture', '07:00');
			    $hrOuv.text('07h 00m').removeClass('editable-empty');

			    updateOpenClose(pk, day + '_fermeture', '23:00');
			    $hrFer.text('23h 00m').removeClass('editable-empty');
			}
			else {
			    console.log('.hr-ouverture-' + day);
			    updateOpenClose(pk, day + '_ouverture', '00:00');
			    $hrOuv.text('...');

			    updateOpenClose(pk, day + '_fermeture', '00:00');
			    $hrFer.text('...');
			}

		    });
		});
	    });

	});

    </script>

    <script type='text/javascript'>
	$(function() {
	    $(['.tda-prevision-ca', '.tda-main-oeuvre', '.tda-nb-transaction']).each(function(k, v) {
		$its = $(v);

		$its.each(function() {
		    var $this = $(this);

		    $this.editable({
			placement: 'top',
			url: "<?php echo $this->url('RHX/default', array('controller' => 'site', 'action' => 'editNumberData')) ?>",
			validate: function(val) {
			    if (!val.length)
				return 'Donnée invalide';
			},
			success: function(val) {
			}
		    });
		});
	    });

	});
    </script>
    
    <script type="text/javascript">
	$(function(){
	    $('#site-documents').click(function(e){
		e.preventDefault();
	    });
	    $('#site-documents').popover({
		html: true,
		title: '<center>Liste des Documents</center>',
		placement: 'right',
		content : function() {
		    ajax = $.ajax({
			type: 'post',
			url: '<?php echo $this->url('RHX/default', array('controller' => 'site', 'action' => 'docList')) ?>',
			data: '&site=<?php echo $site->id ?>'
		    });
		    ajax.done(function(result) {
			$('.popover-content').html(result);
		    });
		}
	    });
	});
    </script>

